﻿Imports System.IO
Imports System.Text
Imports MpqReader
Public Class frmMain
    Public Structure FileListEntry
        Dim Archive As String
        Dim Path As String
        Dim Size As Integer
    End Structure
    Public FileList As New System.Collections.Generic.Dictionary(Of String, FileListEntry)
    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        frmAbout.Show()
    End Sub

    Private Sub OptionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionsToolStripMenuItem.Click
        frmOptions.Show()
    End Sub

    Private Sub WebsiteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WebsiteToolStripMenuItem.Click
        Process.Start("http://www.wowmodelviewer.org")
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "WoW Model Viewer Reloaded :: " + My.Application.Info.Version.ToString
    End Sub

    Private Sub ImportMPQToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportMPQToolStripMenuItem.Click
        frmMPQImport.Show()
    End Sub

    Private Sub txtModelSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtModelSearch.TextChanged
        If txtModelSearch.Text = "" Or txtModelSearch.Text = "Enter a search query..." Then
            tvModelSearch.Hide()
            tvModelSearch.Nodes.Clear()
            tvModelSearch.Nodes.Add("Characters")
            tvModelSearch.Nodes.Add("Creatures")
            tvModelSearch.Nodes.Add("Items")
        Else
            tvModelSearch.Show()
        End If
    End Sub
    Private Sub txtModelSearch_PressedEnter(ByVal sender As System.Object, ByVal e As KeyEventArgs) Handles txtModelSearch.KeyDown
        If e.KeyCode = Keys.Enter Then
            'Dim Ary = 0
            'While Ary <> 5
            Dim MyMPQ As New MPQ
            MyMPQ.PopulateFileList(My.Settings.MPQList(0))
            For Each a As MPQ.FileListEntry In MyMPQ.FileList.Values
                If a.Path.ToLower.Contains(txtModelSearch.Text.ToLower) Then
                    If a.Path.Contains(".m2") Then
                        If a.Path.ToLower.StartsWith("character\") Then
                            tvModelSearch.Nodes(0).Nodes.Add(a.Path)
                        ElseIf a.Path.ToLower.StartsWith("creature\") Then
                            tvModelSearch.Nodes(1).Nodes.Add(a.Path)
                        ElseIf a.Path.ToLower.StartsWith("item\") Then
                            tvModelSearch.Nodes(2).Nodes.Add(a.Path)
                        End If
                    End If
                End If
            Next
            'End While
        End If

    End Sub
End Class